<template>
    <div>
        <input type="text" v-model="color1">
        <input type="text" v-model="color2">
        <h1 v-color="color1">Hello World</h1>
        <p v-color="color2">Welcome to my Vue.js app!</p>
        <button @click="changeColor">同步颜色</button>
    </div>
</template>
<script>
const color = {
  mounted: (el, binding) => {
    el.style.color = binding.value;
  },
  updated: (el, binding) => {
    el.style.color = binding.value;
  }
}
export default {
    name: 'App',
    data() {
        return {
            message: 'Hello from Vue.js!',
            color1:'red',
            color2:'blue'
        }
    },
    methods: {
        changeColor(){
            this.color1 = this.color2;
        }
    },
    directives: {
        color
    }
}
</script>
<style>
</style>